#!/bin/sh

usershell=$SHELL

startup_files() {
  case $(basename $usershell) in
    zsh)
      echo ".zlogin .zshrc .zprofile .zshenv"
      ;;
    bash)
      echo ".bashrc .bash_profile .bash_login .profile"
      ;;
    *)
      echo ".bash_profile .zshrc .profile"
      ;;
  esac
}

install_path() {
  for file in $(startup_files); do
    [ -f $HOME/$file ] || continue
    (grep "Added by the Heroku" $HOME/$file >/dev/null) && break

    cat <<MESSAGE >>$HOME/$file

### Added by the Heroku Toolbelt
export PATH="/usr/local/heroku/bin:\$PATH"
MESSAGE

    # done after we add to one file
    break
  done
}

# if the toolbelt is not returned by `which`, let's add to the PATH
case $(which heroku) in
  /usr/bin/heroku|/usr/local/heroku/bin/heroku)
    ;;
  *)
    install_path
    ;;
esac

# symlink binary to /usr/bin/heroku
ln -sf /usr/local/heroku/bin/heroku /usr/bin/heroku
